/**
 * Created with JetBrains PhpStorm.
 * User: WEI JIAN XIANG
 * Date: 7/14/13
 * Time: 10:08 AM
 * To change this template use File | Settings | File Templates.
 */
$(document).ready(function(){
    $("a[rel^='prettyPhoto']").prettyPhoto({
            theme: 'facebook',
            slideshow:5000,
            autoplay_slideshow:true}
    );
    calculateTotal();
});


function calculateTotal() {
    var final_dunnage_cost = 0;
    $(".final_dunnage_cost").each(function() {
        if ( $(this).val() ) {
            final_dunnage_cost += parseInt($( this ).val());    
        }
    });
    if ( final_dunnage_cost === 0 ) {
        var estimated_dunnage_cost = 0;
        $(".estimated_dunnage_cost").each(function() {
            console.log($(this).val());
            if ( $(this).val() ) {
                estimated_dunnage_cost += parseInt($(this).val());
            }
        });
        $("#totalval").val(estimated_dunnage_cost);
    } else {
        $("#totalval").val(final_dunnage_cost);
    }
}

function moreUpdateDunnage(dunnage_id) {
    $.get(base_url + "/service/more-update-dunnage", {id: dunnage_id, offset: update_dunnage_offset}, function(data) {
        update_dunnage_offset += 3;
        $("#tbl_update_dunnage tbody").append(data);
        var temp = data.match(/\/tr/g);
        var count = temp.length;
        console.log(temp);
        console.log(count);
        if ( count < 3 ) {
            $("#tbl_update_dunnage tfoot").remove();
        }
    });
}